from numpy import *
# import FP-grow-tree.FP_Grow_tree
import sys
sys.path.append("./FP-grow-tree")
import FP_Grow_tree
import pandas as pd
import time

def getListFromXls():
    pFile = "E:/csdn/chaoshi.xls"
    dframe = pd.read_excel(pFile)
    headLst = dframe.columns.values.tolist()
    print(headLst)
    arr = dframe.values
    dataLst = []
    cols = len(headLst)
    for row in range(dframe.shape[0]):
        rowLst = []
        for col in range(cols):
            if arr[row][col] == 'T':
                rowLst.append(headLst[col])
        dataLst.append(rowLst)
    return dataLst

if __name__ == '__main__':
    #print(sample1)
    ##参数说明 sample为事务数据集 []为递归过程中的基,support为最小支持度
    support=100
    timeStart = time.time()
    dataLst = getListFromXls()

    ff=FP_Grow_tree.FP_Grow_tree(dataLst,[],support)
    ##打印频繁集
    ff.printfrequent()
    timeEnd = time.time()
    print("Time: " + str(timeEnd - timeStart) + " sec.")